package com.lanou.dllo.vc.adapter;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by dllo on 15/11/26.
 */
public class EmotionAdapter extends PagerAdapter {

    List<View> gridviews;

    public  EmotionAdapter (List<View> gridviews){
        this.gridviews = gridviews;
        Log.i("lanou","ViewPager中gridview的个数"+ gridviews.size());

    }


    @Override
    public int getCount() {
        return gridviews != null && gridviews.size()>0  ? gridviews.size():0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        ((ViewPager)container).addView(gridviews.get(position));
        return gridviews.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
        ((ViewPager)container).removeView(gridviews.get(position));
    }
}
